#include "../Defines/Init.h"

#ifdef __UX_STL_UNIT_TEST__
#ifdef PLATFORM_ANDROID

#	define _UXS_VARIABLE_ARGUMENTS_H
#	include "../../../ux_stl_core_lib.h"

#	define JNI_ARGS									JNIEnv * env, jobject obj
#	define NATIVE_FUNC_EXT( _app, _object, _func )	Java_##_app##_##_object##_##_func
#	define NATIVE_FUNC( _func )						NATIVE_FUNC_EXT( uxstl_test_app, MainActivity, _func )
#	define NATIVE( _ret, _func )					extern "C" JNIEXPORT _ret JNICALL NATIVE_FUNC( _func )

	using namespace UX_STL;
	using namespace UXTypes;
	using namespace UXMath;
	using namespace Java;

	UX_DECL_JAVA_TYPE( MainActivity_TestClass, "uxstl/test/app/MainActivity$TestClass" );


	JavaObject TestCall (const JavaObject &obj, jmethodID method, ...)
	{
		va_list args;
		va_start( args, method );
		
		//JavaObject	obj1( JavaEnv()->CallObjectMethodV( obj.Get(), method, args ) );
		
		JavaObject	obj1( _java_hidden_::JavaMethodCaller< jobject >::Call( obj, method, args ) );

		va_end( args );
		return obj1;
	}

	void Test_JavaWrappers ()
	{
		JavaEnv	je;

		JavaClass	test_class = JavaClass::FromType< MainActivity_TestClass >();
		JavaObject	obj;

		//obj.Create( test_class );
		JavaObjectConstructor< void (int, int) >	obj_ctor( test_class );

		obj = obj_ctor.Call( 2, 3 );

		//obj.Create< void (int, int) >( test_class, 2, 3 );
		
		JavaMethod< void (jint) >	print_method( obj, "Print" );
		print_method.Call( 10 );
		
		//JavaMethod< MainActivity_TestClass (MainActivity_TestClass) >	self_method( obj, "Self" );
		//JavaObject	obj1( self_method.Call( obj ) );

		typedef JavaMethodType< MainActivity_TestClass (MainActivity_TestClass) >	self_method_type;

		jmethodID self_method = test_class.GetMethodID( "Self", self_method_type::Signature(), false );

		//JavaObject	obj1( je->CallObjectMethod( obj.Get(), self_method ) );

		//JavaObject	obj1( _java_hidden_::JavaMethodCaller< jobject >::Call( obj, self_method, va_list() ) );

		JavaObject		obj1( TestCall( obj, self_method, obj.Get() ) );

		LOG( (string("Result: current: ") << ReferenceCast<usize>(obj) << ", " <<
			ReferenceCast<usize>( obj1.Get() ) ).cstr(), e_log_msg::DEF_ERROR );
	}


	void Test_File (uni_c_string internalStorage)
	{
		string	path	 = "/system/fonts";
		string	filename = path + "/DroidSans.ttf";

		ASSERT( FileSystem::IsDirectoryExist( path ) );

		RFilePtr	file;
		ASSERT( (file = File::HddRFile::New( filename )).IsNotNull() );

		WARNING( (string("file \"") << filename << "\" opened").cstr() );
	}


	NATIVE( void, RunNativeTests ) (jstring internalStorage)
	{
		//UTFString	j_internal_storage( internalStorage );

		Test_File( uni_c_string() );
	}

#endif	// PLATFORM_ANDROID
#endif	// __UX_STL_UNIT_TEST__
